//定义 Store

import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    //用户信息
    const userInfo = ref()
    //清理用户信息
    const clearUserInfo = () => {}

    //记得返回,变量函数都需要返回
    return {
      userInfo,
      clearUserInfo,
    }
  },

  //TODO:持久化
  {
    //网页端配置
    // persist: true
    //小程序端持久化配置
    persist: {
      //调整为兼容多端的APi
      storage: {
        getItem(key) {
          uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
